import { ProFormInstance, ProTable } from '@ant-design/pro-components';
import '@umijs/max';
import { Modal } from 'antd';
import React, { useEffect, useRef } from 'react';

export type prop = {
  values: API.InterfaceInfoVo;
  onCancel: () => void;
  onSubmit: (values: API.InterfaceInfoVo) => void;
  open: boolean;
  columns: API.InterfaceInfoVo[];
};
const UpdateForm: React.FC<prop> = (props) => {
  const { onCancel, onSubmit, open, columns, values } = props;
  // initialValues:只在创建时生效，修改时无效
  // 监听变化
  const formRef = useRef<ProFormInstance>();
  useEffect(() => {
    formRef.current?.setFieldsValue(values);
  }, [values]);
  return (
    <Modal open={open} onCancel={() => onCancel()}>
      <ProTable
        type={'form'}
        formRef={formRef}
        columns={columns}
        onSubmit={(values) => {
          onSubmit(values);
        }}
      />
    </Modal>
  );
};
export default UpdateForm;
